package com.loveprogrammer.eternity.skill.support.skills.passive;

import com.loveprogrammer.eternity.enums.QualityEnum;
import com.loveprogrammer.eternity.factory.MonsterFactory;
import com.loveprogrammer.eternity.factory.template.MonsterTemplate;
import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.model.Monster;
import com.loveprogrammer.eternity.common.Tuple;
import com.loveprogrammer.eternity.utils.BeanCopyUtils;
import com.loveprogrammer.eternity.utils.RandomBalance;

import java.io.IOException;
import java.util.*;

/**
 * @version 1.0.0
 * @description: 骷髅召唤
 * @author: eric
 * @date: 2022-12-22 11:31
 **/
public class SkillSkeletalCall extends AbstractPassiveCallSkill {
    private List<Integer> qualitys = Arrays.asList(1600,800,400,200,100);

    public SkillSkeletalCall(int id, int baseInterval, int level, int order, int maxLevel, String name, String desc) {
        super(id, baseInterval, level, order, maxLevel, name, desc);
    }

    @Override
    public boolean checkLevelUp(int characterLevel) {
        // 每2级升一级
        // if (characterLevel % 2 == 0) {
            return true;
        // }
        // return false;
    }

    @Override
    protected Tuple<String, List<Character>> skillLaunch(Character character,
                                                         List<? extends Character> attack,
                                                         List<? extends Character> defences) {
        Tuple<String, List<Character>> tuple = new Tuple<>();

        StringBuilder builder = new StringBuilder();
        List<Character> characters = new ArrayList<>(attack);
        builder.append("技能").append(getName()).append("(").append(getLevel()).append("级)释放");
        int increment = getHarm(character);
        // 召唤 30级 骷髅战士 30级+ 战士+法师
        if (getLevel() < 20) {
            callWarriors(character, builder, characters, increment);
        } else if (getLevel() < 50) {
            // 狼 + 熊 熊的等级是（技能等级-10）/2 + 1
            callWarriors(character, builder, characters, increment);
            // callBeer(character, builder, characters, increment);
        } else {
            // 狼 + 熊
        }
        // 收到普通攻击，减少伤害
        tuple.setValue(characters);
        tuple.setKey(builder.toString());
        return tuple;
    }

    @Override
    protected int computeHarm(Character character) {
        return getLevel() * 10;
    }

    @Override
    protected int computeSecondHarm(Character character) {
        return 0;
    }

    private void callBeer(Character character, StringBuilder builder, List<Character> characters, int increment) {
        // 熊的等级是技能等级/2 + 1 数量是（技能等级/5 + 1） 一只熊 技能等级越高 召唤出高质量的熊的机率越大
    }

    private void callWarriors(Character character, StringBuilder builder, List<Character> characters, int increment) {
        // 最多5个骷髅
        int num = Math.min(getLevel() / 6 + 1,5);
        int level = getLevel();
        // 骷髅战士 每一级增加不同的基础值
        int id = 90010;
        for (int i = 0; i < num; i++) {
            MonsterTemplate template = null;
            try {
                template = BeanCopyUtils.deepCopy(MonsterFactory.getById(id));
            } catch (Exception e) {
                e.printStackTrace();
                continue;
            }
            template.setLevelUpArmature((int) (template.getLevelUpArmature() + level * 1.3));
            template.setLevelUpMagic(0);
            template.setLevelUpConstitution((int) (template.getLevelUpConstitution() + level * 1.8));
            template.setLevelUpSpeed((int) (template.getLevelUpSpeed() + level * 1.5));
            template.setLevelUpStrength((int) (template.getLevelUpStrength() + level * 1.9));
            template.setLevelUpTechnique((int) (template.getLevelUpTechnique() + level * 1.4));
            QualityEnum quality = RandomBalance.findQuality(qualitys.get(0) + increment,
                    qualitys.get(1) + increment, qualitys.get(2) + increment,
                    qualitys.get(3) + increment, qualitys.get(4) + increment
                    , 0, 0);
            Monster monster = MonsterFactory.createMonster(template, level, quality, true);
            builder.append(monster.toString()).append("加入战团").append("\n");
            characters.add(monster);
        }
    }
}
